package com.zjc.yohoshop.mvp.view.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zjc.yohoshop.R;
import com.zjc.yohoshop.bean.AddressListEntity;
import com.zjc.yohoshop.mvc.control.SPHelperSave;


/**
 * 地址管理适配器
 */
public class AddressSelectorAdapter extends BaseQuickAdapter<AddressListEntity.ValuesBean, BaseViewHolder> {
    public AddressSelectorAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, AddressListEntity.ValuesBean item) {
        TextView tag = helper.getView(R.id.tv_item_address_selector_address_tag);

        if (SPHelperSave.getInstance().getAddress_default().equals(item.address_id)){
            tag.setVisibility(View.VISIBLE);
        }else{
            tag.setVisibility(View.GONE);
        }

        helper.setText(R.id.tv_item_address_selector_user_name, "*" + item.user_name.substring(1));
        helper.setText(R.id.tv_item_address_selector_phone, item.phone.substring(0, 3) + "****" + item.phone.substring(6));
        helper.setText(R.id.tv_item_address_selector_address_area, item.address_area);
        helper.setText(R.id.tv_item_address_selector_address_detail, item.address_detail);

        CheckBox address_default = helper.getView(R.id.cb_item_address_selector_address_default);
        if ("1".equals(item.address_default)){
            address_default.setChecked(true);
        }else{
            address_default.setChecked(false);
        }

        helper.addOnClickListener(R.id.cb_item_address_selector_address_default);
        helper.addOnClickListener(R.id.iv_item_address_selector_address_edit);

    }
}
